package lcr;

import java.util.ArrayList;
import java.util.List;

public class Test0083 {
}

class Solution0083_1 {
    List<List<Integer>> ans= new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {
        backtrack(nums,0,new ArrayList<>(nums.length));
        return ans;
    }
    public void backtrack(int[] nums,int records,List<Integer> list) {
        int size = list.size();
        int length = nums.length;
        if (size == length) {
            ans.add(new ArrayList<>(list));
            return;
        }

        for (int i = 0; i < length; i++) {
            int flag = 1 << i;
            if ((flag &records)>0) continue;

            records|=flag;
            list.add(nums[i]);

            backtrack(nums,records,list);

            list.remove(size);
            records^=flag;
        }

    }
}
